package com.dst.note;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

/**
 * Service和Broadcast都行，此处选一个，service存活率更高
 */
public class ClockService extends Service {
    private static final String TAG = "ClockService";
    public static final String EXTRA_EVENT_ID = "extra_event_id";

    public ClockService() {
        Log.d(TAG, "ClockService: Constructor");
    }

    @Override
    public IBinder onBind(Intent intent) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        WakeLockUtil.wakeUpAndUnlock();

        postToClockActivity(getApplicationContext(),intent);
        return super.onStartCommand(intent, flags, startId);
    }

    private void postToClockActivity(Context context, Intent intent) {
        String noteId = intent.getStringExtra(ClockService.EXTRA_EVENT_ID);
        Log.e("tgl===", "service id: " + noteId);
        Intent i = new Intent();
        i.setClass(getApplicationContext(), ClockActivity.class);
        i.putExtra(ClockService.EXTRA_EVENT_ID, noteId);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}
